<template>
    <div class="container">
        <!-- 导航栏区域开始 -->
        <TridentNavBar>
            <template #left><i class="iconfont icon-zuojiantou"></i></template>
            <template #default>申请添加好友</template>
        </TridentNavBar>
        <!-- 导航栏区域结束 -->

        <!-- 申请内容区域开始 -->
        <div class="apply-wrap">
            <van-field
                v-model="params.apply"
                label="发送添加好友申请"
                placeholder="请输入"
                label-align="top"
                rows="2"
                type="textarea"
                maxlength="50"
                show-word-limit
            />
        </div>
        <!-- 申请内容区域结束 -->

        <!-- 设置备注区域开始 -->
        <div class="note-wrap">
            <van-field
                v-model="params.note"
                label="设置备注"
                placeholder="请输入"
                label-align="top"
            />
        </div>
        <!-- 设置备注区域结束 -->

        <!-- 添加标签与描述区域开始 -->
        <div class="label-wrap">
            <div class="title-box">添加标签与描述</div>
            <TridentCellItem :item="{title: '标签'}"/>
            <TridentCellItem :item="{title: '描述'}"/>
        </div>
        <!-- 添加标签与描述区域结束 -->

        <!-- 设置好友权限区域开始 -->
        <div class="permission-wrap">
            <div class="title-box">设置好友权限</div>
            <div class="item-box">
                <span>聊天、好友圈</span>
                <i class="iconfont icon-duigou"></i>
            </div>
            <div class="item-box">
                <span>仅聊天</span>
                <i class="iconfont icon-duigou"></i>
            </div>
        </div>
        <!-- 设置好友权限区域结束 -->

        <!-- 发送按钮 -->
         <div class="btn-wrap">
            <div class="btn" @click="handleSendApply">发送</div>
         </div>
    </div>
</template>

<script lang="ts" setup>
import { reqAddFriendApplyAPI } from '@/apis/friendApply'
import { useUserStore } from '@/store/modules/user'
import type { AddFriendApplyParams } from '@/types/friendApply'
import { showSuccessToast } from 'vant'
import { reactive } from 'vue'
import { useRoute, useRouter } from 'vue-router'

// 路由
const route = useRoute()

// 路由器
const router = useRouter()

// 用户存储
const userStore = useUserStore()

// 添加好友申请参数
const params = reactive<AddFriendApplyParams>({
    respondent_id: route.query.uid as never,
    label: '',
    desc: '',
    permission: [],
    apply: '我是' + userStore.profile.user.username,
    note: ''
})

// 处理发送申请
const handleSendApply = async () => {
    await reqAddFriendApplyAPI(params)
    showSuccessToast('申请成功')
    setTimeout(() => {
        router.push('/')
    }, 1000)
    
}
</script>

<style scoped lang="scss">
page,
.container {
    height: 100vh;
    .apply-wrap {
        padding: 60px 10px 0 10px;
    }

    // 设置备注区域开始
    .note-wrap {
        padding: 10px 10px 0 10px;
    }

    // 添加标签与描述区域开始
    .label-wrap {
        margin: 10px 10px 0 10px;
        padding: 10px;
        border-radius: 10px;
        background-color: #fff;
        .title-box {
            font-size: 14px;
            border-bottom: 1px solid #f6f6f6;
            padding-bottom: 10px;
        }
    }

    // 设置好友权限区域开始
    .permission-wrap {
        margin: 10px 10px 0 10px;
        padding: 10px;
        border-radius: 10px;
        background-color: #fff;
        .title-box {
            font-size: 14px;
            border-bottom: 1px solid #f6f6f6;
            padding-bottom: 10px;
        }

        .item-box {
            display: flex;
            padding: 15px 10px;
            border-bottom: 1px solid #f6f6f6;
            color: #000;
            justify-content: space-between;
            align-items: center;
            &:last-child {
                border-bottom: none;
            }
            .iconfont {
                color: #27BA9B;
                font-size: 20px;
            }
        }
    }

    .btn-wrap {
        margin: 15px;
        display: flex;
        justify-content: center;
        .btn {
            width: 60%;
            padding: 10px 0;
            background-color: #27BA9B;
            color: #fff;
            font-size: 20px;
            border-radius: 8px;
            text-align: center;
        }
    }
}
</style>